export default {
	data() {
		return {
			//记事本列表
			notepadList:'',
			//记事本
			notepad:'',
			
			//是否打开书写框
			writeShow:false,
			//是否打开记事本详情页
			readShow:false,
			//确认删除框
			deleteShow:false,
			
			title:'',
			content:'',
			
			notepadContent:'',
			
			current: 0,
			downList: [{
					iconPath: "file-text",
					selectedIconPath: "file-text-fill",
					text: '文件',
					customIcon: false,
					pagePath: '/pages/index/index'
				},
				{
					iconPath: "edit-pen",
					selectedIconPath: "edit-pen-fill",
					text: '笔记',
					customIcon: false,
					pagePath: '/pages/notepad/notepad'
				},
				{
					iconPath: "account",
					selectedIconPath: "account-fill",
					text: '我的',
					customIcon: false,
					pagePath: '/pages/user/user'
				}
			],
		}
	},
	onShow() {
		this.headImg = uni.getStorageSync('headImg');
		this.nickName = uni.getStorageSync('nickName');
		this.userId = uni.getStorageSync('userId');
		this.token = uni.getStorageSync('token');
		this.userUuid = uni.getStorageSync('userUuid');
		this.phone = uni.getStorageSync('phone');
		this.email = uni.getStorageSync('email');
		this.dataLocation = uni.getStorageSync('dataLocation');
		
		setTimeout(() => {
			this.listNotepad();
		}, 500);
	},
	methods: {
		async beforeSwitch(index) {
			switch (index) {
				case 0:
					break;
				case 1:
					break;
				case 2:
					break;
			}
			return true;
		},
		//获取记事本列表
		listNotepad(){
			this.$request('/Notepad/listNotepadByUserId', {
					"userId": this.userId
				})
				.then(res => {
					if (res.code == 200) {
						this.notepadList = res.data
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})
				.catch(e => {
					uni.showToast({
						title: '错误',
						icon: 'none',
						duration: 2000
					});
				});
		},
		//打开书写框
		openWrite(){
			this.writeShow = true;
		},
		insertNotepad(){
			this.$request('/Notepad/insertNotepad', {
					"userId": this.userId,
					"notepadTitle":this.title,
					"notepadContent":this.content,
				})
				.then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
						this.writeShow = false;
						this.listNotepad();
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})
				.catch(e => {
					uni.showToast({
						title: '错误',
						icon: 'none',
						duration: 2000
					});
				});
		},
		//获取该记事本详情
		getNotepadByUuid(e){
			this.$request('/Notepad/getNotepadByUuid', {
					"notepadUuid":e
				})
				.then(res => {
					if (res.code == 200) {
						this.notepad = res.data;
						this.readShow = true;
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})
				.catch(e => {
					uni.showToast({
						title: '错误',
						icon: 'none',
						duration: 2000
					});
				});
		},
		//修改记事本
		updateNotepadByUuid(e){
			this.$request('/Notepad/updateNotepadByUuid', {
					"notepadUuid":e.notepadUuid,
					"notepadTitle":e.notepadTitle,
					"notepadContent":e.notepadContent
				})
				.then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
						this.listNotepad();
						this.readShow = false;
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})
				.catch(e => {
					uni.showToast({
						title: '错误',
						icon: 'none',
						duration: 2000
					});
				});
		},
		//打开删除确认框
		openDelete(){
			this.readShow = false;
			this.deleteShow = true;
		},
		deleteNotepadByUuid(e){
			this.$request('/Notepad/deleteNotepadByUuid', {
					"notepadUuid":e.notepadUuid
				})
				.then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
						this.listNotepad();
						this.readShow = false;
						this.deleteShow = false;
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})
				.catch(e => {
					uni.showToast({
						title: '错误',
						icon: 'none',
						duration: 2000
					});
				});
		}
	}
}
